﻿using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UMLSynthesizer.CSharpAnalyzer.Elements;
using UMLSynthesizer.CSharpAnalyzer.Helpers;
using UMLSynthesizer.LangAnalyzer.Elements;
using UMLSynthesizer.LangAnalyzer.Statements;

namespace UMLSynthesizer.CSharpAnalyzer.Statements
{
    class CSharpCatchClause : CSharpStatementBase, ICatchClause
    {
        #region Fields

        CatchClauseSyntax catchBlock;
        CSharpStatementBlockHelper blockHelper;

        #endregion

        #region Constructor

        public CSharpCatchClause(CatchClauseSyntax catchBlock, IStatementBase parentStatement)
            : base(null, parentStatement, null, StatementKinds.Catch)
        {
            this.catchBlock = catchBlock;
            blockHelper = new CSharpStatementBlockHelper(this,
                () => catchBlock.Block.Statements);
        }

        #endregion

        #region Properties

        public bool HasType { get { return catchBlock.Declaration != null; } }
        public ITypeBase Type
        {
            get
            {
                if (!HasType) return null;
                return (ProjectOwner as CSharpProjectElement).GetTypeReference(catchBlock.Declaration.Type);
            }
        }
        public IEnumerable<IStatementBase> ContainedStatements { get { return blockHelper.ContainedStatements; } }

        #endregion
    }
}
